package fr.uvsq.isty.bdh.hchess.ics;

import fr.uvsq.isty.bdh.hchess.interfacing.*;
import ictk.boardgame.chess.ChessBoard;
import java.net.ProtocolException;

/**
 *
 * @author Florent Hemmi <florent.hemmi@gmail.com>
 */
public class ICSchessPlayer implements IChessPlayer {
    
    private GameEventRefereeNotifier notifier;
    
    private ICSclient ics;
    
    public ICSchessPlayer(ICSclient ics) throws ProtocolException {
        this.ics = ics;
    }

    public boolean sendsChat() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean recivesChat() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void notifyChatRecived(String message) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getChat() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean handlesNonStandardStarts() {
        return false;
    }

    public void setUp(GameEventRefereeNotifier notifier) throws BadStateException {
    }

    public void setUp(GameEventRefereeNotifier notifier, ChessBoard startPos) throws BadStateException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int[] getNextMove(int[] lastMove) {
        String ret = "";
        ret += String.valueOf((char)(lastMove[0]+'a'-1));
        ret += String.valueOf((char)(lastMove[1]+'1'-1));
        ret += String.valueOf((char)(lastMove[2]+'a'-1));
        ret += String.valueOf((char)(lastMove[3]+'1'-1));
        
        ics.sendCommand(ret);
        
        return null;
    }

    public void notifyFinalMove(int[] lastMove){
        
    }

    public int[] getNextMove(int[] lastMove, int timeLimit) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void notifyGameEvent(GameEvent event) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean handlesResume() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setUp(GameEventRefereeNotifier notifier,
            ChessBoard startPos,
            int[][] stateToRestore) throws FailedToReachPlayerException {
        this.notifier = notifier;
        if (!ics.isLoggedIn()) {
            throw new FailedToReachPlayerException(
                    "Not logged in on the server.");
        }
        System.out.println("[Client] Success!");
        ics.sendCommand("match sordid atomic 3 0 unrated");
    }
    
}
